package org.grow.sha.service;

import org.grow.sha.entity.Account;
import org.grow.sha.serviceAop.Modal;
import org.grow.sha.serviceAop.Tab;
import org.grow.sha.serviceAop.ValidatePosition;
import org.grow.sha.tool.RobotEx;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.awt.*;

import static org.grow.sha.service.TaskExeService.corePoint;

@Component
public class RedActivity {
    @Autowired
    private RobotEx robot;
    Logger logger = LoggerFactory.getLogger(RedActivity.class);

    public final static Color dailyTaskColor1 = new Color(107, 145, 72);
    @Modal
    @ValidatePosition
    public void flowerPresent(Account account){
//        开始给好友送鲜花
//        点击好友按钮
        robot.moveAndClick(855, 743);
//        如果有人正在申请加好友　则删除
//        目标点　392 357 107 145 72
//        空闲点　300 227
        while (true) {
            Color pi = robot.getPixelColor(392, 357);
            if (robot.closeTo(pi, dailyTaskColor1)) {
//                点击拒绝按钮
                robot.moveAndClick(468, 361);
//                返回空闲点
                robot.moveAndClick(300, 227);
                logger.info(account.getUsername()+" 拒绝了一个好友的邀请");
            } else {
                break;
            }
        }
//        选择最上面的一个好友
        robot.moveAndClick(335, 317);
        robot.delay(1000);
//        选择赠送鲜花
        robot.moveAndClick(1067, 275);
//        点击确定
        robot.moveAndClick(718, 561);
//        等待动画
        robot.delay(1000);
        robot.moveAndClick(704,545);
        robot.delay(2000);
//        关闭好友界面
        robot.moveAndClick(1143, 231);
        logger.info(account.getUsername() + " 赠送鲜花");
//        robot.moveAndClick(TaskExeService.relaxPoint.x,TaskExeService.relaxPoint.y);
    }
    @Modal
    @ValidatePosition
    public void speech(Account account,String content){
        //        点击小三角展开聊天框
        robot.moveAndClick(660, 696);
//        点击综合发言
        robot.moveAndClick(186, 439);
//        聚焦发言框
        robot.moveAndClick(330, 744);
//        输入内容
        robot.input(content);
//        点击发送按钮
//
        robot.moveAndClick(608, 744);
//        多加一步　有的口令会有奖励　
        robot.delay(1000);
        robot.moveAndClick(672, 750);
//        最小化聊天框
        robot.moveAndClick(660, 444);
        logger.info(account.getUsername()+"发言："+content);
    }
    @Tab
    @ValidatePosition
    public void unionAbout(Account account) {
//        todo: 这边有两个状态 一个是红包提示 一个是任务提示 都是红色 但不相同 会覆盖
//        首先判断是否有红包 如果有红包就进去 再次判断是否有红点 有红点也进去


//        r=185,g=2,b=2;
//        Color pixelColor = robot.getPixelColor(910, 729);
//        if (pixelColor.getGreen() < 10 && pixelColor.getBlue() < 10) {

            robot.moveAndClick(910, 729);
            robot.delay(2000);
//            java.awt.Point[x=1200,y=613]
//java.awt.Color[r=204,g=1,b=1]
//            三捐
            Color boom = robot.getPixelColor(1200, 613);
            if (boom.equals(new Color(204, 1, 1))) {
                for (int i = 0; i < 3; i++) {
                    robot.moveAndClick(1200, 580);
                }
                logger.info(account.getUsername() + "完成了三擂鼓");
            }
            robot.delay(1000);
            robot.moveAndClick(1049, 340);
//            todo:领取工会红包
//            确保公告关闭
            Color ad = robot.getPixelColor(636, 304);
            if (ad.equals(new Color(41, 21, 19))) {
                robot.moveAndClick(1015, 264);
                robot.moveAndClick(1049, 340);
            }
            Color ce = robot.getPixelColor(832, 259);
//         　   要么是r=84,g=135,b=38 绿色 要么是　82,71,54
//            点击只看红包
            if (ce.getGreen() < 120) {
                System.out.println("只看红包　" + ce);
                robot.moveAndClick(832, 259);
                robot.delay(5000);
                robot.moveAndClick(1049, 340);
            }

//            Color dark = new Color(87, 71, 70);
//            106,g=27,b=25
            Color redToGet = new Color(106, 27, 25);
//             robot.moveAndClick(900, 360);
//                robot.moveAndClick(900, 465);
//                robot.moveAndClick(900,570);
            for (int i = 0; i < 3; i++) {
                Color cbag = robot.getPixelColor(910, 360 + (i * 105));
                if (cbag.equals(redToGet)) {
//                if (!cbag.equals(dark)) {
                    robot.moveAndClick(910, 330 + (i * 105));
                    robot.click();
                }
            }
            robot.moveAndClick(1049, 340);
//            领取每日任务
            for (int i = 0; i < 3; i++) {
                robot.moveAndClick(1238, 220 + (i * 90));
            }
//java.awt.Color[r=106,g=27,b=25] 可领取的红包颜色　－》　不可领取的颜色[r=87,g=71,b=70]
//            只看红包　按钮　８２８　２６５

            robot.delay(1000);
//            返回
//            robot.moveAndClick(194, 655);

    }
    public static final Color elegantColor1 = new Color(197, 2, 2);
    public static final Color elegantColor2 = new Color(56,53,73);

    @Tab
    @ValidatePosition
    public void elegantAbout(Account account) {
//        Color c = robot.getPixelColor(1183, 562);
//
//        if (c.equals(elegantColor1)) {
//            robot.moveAndClick(1170, 585);
//            robot.delay(2000);
//            robot.moveAndClick(550, 500);
//            robot.delay(2000);
//            robot.moveAndClick(200, 635);
//            robot.delay(2000);
//            logger.info(account.getUsername() + "领取一套三国秀");
//            robot.moveAndClick(corePoint.x, corePoint.y);
//        }
//        robot.delay(1000);
        robot.moveAndClick(1170,585);
        robot.delay(2000);
//        new Color(56,53,73) 621 540
        Color p = robot.getPixelColor(621, 540);
        if (robot.closeTo(elegantColor2,p)){
            robot.moveAndClick(550,500);
            robot.delay(3000);
            robot.moveAndClick(200,635);
            robot.delay(1000);
//            一个空闲点
            robot.moveAndClick(783,614);
            logger.info(account.getUsername() + "领取一套三国秀");
        }else {
            robot.createDebugSnapShot("elegant");
            logger.info(account.getUsername()+"没有领取免费三国秀 "+p);
        }
    }


}
